<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/9/23 0023
  Time: 20:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fnt" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <title>问题管理</title>
    <link rel="stylesheet" href="/manage/css/static/question-type/question.manage.main.css">
    <link rel="stylesheet" href="/manage/css/static/question-type/zTreeStyle.css">
    <script src="/manage/js/lib/question-type/jquery-3.4.1.min.js"></script>
    <script src="/manage/js/lib/question-type/jquery.ztree.core.min.js"></script>
    <script src="/manage/js/lib/question-type/jquery.ztree.excheck.min.js"></script>
    <script src="/manage/js/lib/question-type/test-1.1.js"></script>
    <script type="text/javascript" src="/manage/js/lib/laypage/1.2/laypage.js"></script>
    <!--_footer 作为公共模版分离出去-->
    <!--/_footer 作为公共模版分离出去-->
    <script type="text/javascript" src="/manage/js/lib/html5shiv.js"></script>
    <script type="text/javascript" src="/manage/js/lib/respond.min.js"></script>
    <link rel="stylesheet" type="text/css" href="/manage/css/static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="/manage/css/static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="/manage/js/lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="/manage/css/static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="/manage/css/static/h-ui.admin/css/style.css" />

    <script type="text/javascript" src="/manage/js/lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
</head>
<body>
<div style="float: left">
    <h3 style="text-align: center;color: #3b4249;">下方选择问题类型</h3>
    <ul id="treeDemo" class="ztree"></ul>
</div>
<div style="width:720px;margin-left: 20px;float: left;">
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 题库管理 <span class="c-gray en">&gt;</span> 问题列表管理<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
    <div class="page-container">
        <div class="text-c">问题查询：
            <input type="text" class="input-text" style="width:250px" placeholder="输入问题标题关键字" id="" name="">
            <button type="submit" class="btn btn-success" name=""><i class="Hui-iconfont">&#xe665;</i> 搜问题</button>
        </div>
        <input type="hidden" class="question-type">
        <div class="cl pd-5 bg-1 bk-gray mt-20">
            <span class="l">
                <a href="javascript:;" onclick="datadel()" class="btn btn-danger radius">
                    <i class="Hui-iconfont">&#xe6e2;</i> 批量删除
                </a>
                <a href="/manage/question/question-add" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加问题
                </a>
            </span>
            <div class="mt-20" id="mt-20">

            </div>
        </div>
    </div>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="/manage/js/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="/manage/css/static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="/manage/css/static/h-ui.admin/js/H-ui.admin.js"></script>
<!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/manage/js/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="/manage/js/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
</body>
</html>
<script>
    $(function () {
        //zTree的配置
        var setting = {
            view: {
                selectedMulti: false
            },
            edit: {
                enable: true,
                editNameSelectAll: true,
            },
            data: {
                simpleData: {
                    enable: true
                }
            },
            callback: {
                onClick:zTreeOnClick, //点击选中事件　
            }
        };
        //zTree初始化加载的节点树

        var zNodes =[
            <c:forEach items="${questionTypeList}" var="questionType" varStatus="stat">
            {id:${questionType.id},pId:${questionType.pId},name:"${questionType.name}", open:true},
            </c:forEach>
        ];

        //问题的多条件搜索
        //页面加载完成后执行，有条件，第一页
        initData(null,null,null);
        var log, className = "dark";
        function zTreeOnClick(event, treeId, treeNode) {
            var questionTypeId=treeNode.id;
            var pid=treeNode.pId;
            if(questionTypeId!=1&&pid!=1){
                $(".question-type").val(questionTypeId);
            }
            var subject=$(".input-text").val();
            if(subject==""){
                subject=null;
            }
            initData(subject,1,questionTypeId);
        }

        $(function(){ //初始化加载树bai
            $.fn.zTree.init($("#treeDemo"), setting, zNodes);  //加载树节点信息
            var zTree=$.fn.zTree.getZTreeObj("treeDemo");
        });


        //点击分页,可能有条件
        $("#mt-20").on("click",".list-page a",function () {
            var pageNum=$(this).attr("data");
            var subject=$(".input-text").val();
            if(subject==""){
                subject=null;
            }
            var questionTypeId=$(".question-type").val();
            if(questionTypeId==""){
                questionTypeId=0;
            }
            initData(subject,pageNum,questionTypeId);//问题的多条件搜索
            return false;
        });
        //点击查询，有条件，第一页
        $(".btn-success").click(function () {
            var subject=$.trim($(this).prev().val());
            if(subject==""){
                subject=null;
            }
            var questionTypeId=$(".question-type").val();
            if(questionTypeId==""){
                questionTypeId=0;
            }
            initData(subject,1,questionTypeId);
        });
        function initData(subject,pageNum,questionTypeId) {
            var data={subject:subject,pageNum:pageNum,questionTypeId:questionTypeId};
            $.post("/manage/question/question-list-page",data,function (mes) {
                $("#mt-20").html(mes);
            });
        }

    });
    //获取ids,批量删除
    function datadel() {
        var ids='';
        $('input:checkbox').each(function () {
            if(this.checked==true){
                ids+=this.value+',';
            }
        });
        if(ids==''){
            layer.alert("请选择删除选项");return;
        }
        var strs_ids=new Array();
        var str_1=ids.replace(/\s*/g,"");//去掉空格-字符串
        var str_2=str_1.replace(/^,+/,"").replace(/,+$/,"");//去掉首尾逗号
        strs=str_2.split(",");
        for (i = 0; i <strs.length ; i++) {
            //分割后的字符串输出
            strs_ids.push(strs[i]);
        }
        var ids=strs_ids.toString();
        layer.confirm('批量删除后不可恢复，谨慎操作!',function (index) {
            var data={ids:ids};
            $.ajax({
                type:'post',
                url:'/manage/question/batch-question',
                data:data,
                success:function(data){
                    $("input[name=check]").each(function () {
                        if(this.checked==true){
                            $(this).parent().parent().remove();
                        }
                    });
                    layer.msg('已删除!',{icon:1,time:1000});
                    $("input:checkbox[name=select]").prop("checked",false);
                }
            });
        });
    }
</script>
